import { useRef, useEffect } from 'react';







let _createdCount = 0;
let _destroyedCount = 0;

const resetDomTrackStats = () => {
  _createdCount = 0;
  _destroyedCount = 0;
};

const getDomTrackStats = () => ({
  created: _createdCount,
  destroyed: _destroyedCount,
  reused: 0, 
});

window.domTrackStats = {
  reset: resetDomTrackStats,
  get: getDomTrackStats,
  created: 0, 
  destroyed: 0, 
  reused: 0, 
};


export const useDomTracker = (id) => {
  const ref = useRef(null);

  useEffect(() => {
    
    _createdCount++;
    window.domTrackStats.created = _createdCount;
    

    return () => {
      
      _destroyedCount++;
      window.domTrackStats.destroyed = _destroyedCount;
      
    };
  }, [id]); 

  return ref;
};


export const domTrackStatsGlobal = window.domTrackStats;